﻿using Common.Class;
using Common.Model;

namespace RdpClient.BLL
{
    public class SessionBLL
    {

        public static List<SessionModel> SessionList = null;

        public static string LoginPassword = "";

        public static List<SessionModel> SessionListGet()
        {
            string _s = StringHelper.Decompress(FileHelper.FileTextRead(FileHelper.GetRunPath() + @"\SessionInfo"));
            JsonHelper _json = new JsonHelper(EncryptHelper.DecryptString_Aes(_s, "JLSoft"));
            LoginPassword = _json.GetVar("LoginPassword");
            List<SessionModel> _sessionList = JsonHelper.GetObjectFromJsonStr<List<SessionModel>>(_json.GetVar("SessionList"));
            if (_sessionList == null)
            {
                _sessionList = new List<SessionModel>();
            }
            SessionList = _sessionList;
            return _sessionList;
        }


        public static void SessionListSave(List<SessionModel> modelList)
        {
            SessionList = modelList;
            string _sessionList = JsonHelper.GetJsonStrFromObject(modelList);
            string _json = new JsonHelper()
                .AddVar("SessionList", _sessionList)
                .AddVar("LoginPassword", LoginPassword)
                .JsonStr;
            string _data = EncryptHelper.EncryptString_Aes(_json, "JLSoft");
            string _sZip = StringHelper.Compress(_data);
            FileHelper.FileTextWrite(FileHelper.GetRunPath() + @"\SessionInfo", _sZip);
        }

    }
}
